import time

from commom.base import Base,open_browser
login_url = "http://ecshop.itsoso.cn/user.php"


class OrderPage(Base):
    """封装表现层,著作定位器"""
    username_loc = ("name","username")# 用户名输入框
    password_loc = ("name","password")# 密码输入框
    submit_loc = ("name","submit")# 立即登录按钮
    home_page_loc = ("link text","首页")# 定位到首页
    UAV_loc = ("css selector", "div.img-box")  # 定位到无人机
    purchase_loc = ("css selector", "td.td1")  # 立即购买按钮
    remember_loc = ("id","remember")# 点击记住密码
    settlement_loc = ("css selector","img[alt='checkout']")# 点击结算
    address_loc = ("css selector","input[value='5']")# 点击申通快递
    balance_loc = ("css selector","input[value='1']")# 点击余额支付
    sbmission_loc = ("css selector","input[type='image']")






    """封装操作层,每一个元素操作方法写成一个方法"""
    def input_username(self,text):
        """输入用户名"""
        self.send_keys(self.username_loc,text)
    def input_password(self,text):
        """输入密码"""
        self.send_keys(self.password_loc,text)
    def click_remember(self):
        # 点解记住密码
        self.click(self.remember_loc)

    def click_submit(self):
        """点击登录按钮"""
        self.click(self.submit_loc)
    def click_UAV(self):
        """点击无人机商品"""
        self.click(self.UAV_loc)
    def click_home_page(self):
        """点击立即购买按钮"""
        self.click(self.home_page_loc)
    def click_settlement(self):
        """点击结算按钮"""
        self.click(self.settlement_loc)

    def click_purchase(self):
        # 点击立即购买按钮
        self.click(self.purchase_loc)
    def click_address(self):
        # 点击申通快递
        self.click(self.address_loc)
    def click_balance(self):
        # 点击余额支付
        self.click(self.balance_loc)
    def click_sbmission(self):
        # 点击提交订单
        self.click(self.sbmission_loc)


if __name__ == '__main__':
    # from ECshop.common.base import open_browser
    driver = open_browser()
    login = OrderPage(driver)
    login.open_url(login_url)
    # 输入账号
    login.input_username("codewen")
    # 输入密码
    login.input_password("admin123456")
    # 点击立即登录按钮
    login.click_submit()
    # time.sleep(5)
    # 点击首页按钮
    login.click_home_page()
    # 点击无人机商品
    login.click_UAV()
    # 点击立即购买按钮
    login.click_purchase()
    # 点击结算按钮
    login.click_settlement()
    # 点击申通快递
    login.click_address()
    # 点击余额支付
    login.click_balance()
    # 点击提交订单
    login.click_sbmission()

    # 关闭浏览器
    # login.close_browser()